//********************************************************
// PopupMenu.java
// Date: 4/17/2012
// Author: Jeff Xiong
//********************************************************
// Popup menu which displays the current contents of the players hand.
// Upon selecting a choice it uses Tile.java to place the proper image on the 
// board at the specified board location.
// ******************************************************
package ui;

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Toolkit;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.io.Serializable;
import java.util.ArrayList;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;

import functionality.Player;
import ui.Tile;


public class MakePlayers implements Serializable{
	
	private static JPanel play;	
	
	private static ArrayList<JFrame> playerScreen = new ArrayList<JFrame>();
	static ArrayList<Player> players = new ArrayList<Player>();
	private static int _playsize = 0;
	private static int _size = 0;
	private static Color c1;
	private static Color c2;
	private static Color c3;
	private static Color c4;
	static boolean done=true;
	private static int xOffsetA=100;
	private static int xOffsetB=100;
	private static int yOffset=200;
	
	
	
	
	/**
	 * Initialize new player frames based on number of players
	 * 
	 * @param none
	 * @return none
	 */
	public MakePlayers(int size)
	{
		_size=size;
		for (int i = 0; i < _size; i++) {
			playerScreen.add(new JFrame(/* "Player "+(i+1)) */));
			
		}
	

		// final int count=1;
		for (int i = 0; i < playerScreen.size(); ++i) {
			final int p = i;
			final int count = i + 1;	
			done=false;
			makePlayers(p, count);
				
			
			//waits for player to choose color
			if (i == 0)
				while (c1 == null ) {;};
			if (i == 1)
				while (c2 == null) {};
			if (i == 2)
				while (c3 == null) {};
				
		
		}

		// wait till number of players are determined
		//while (_size == 0) {}

		// wait till players are initialized
		while (_playsize != _size) {}
		
	}
	
	
	/**
	 * Get current player
	 * 
	 * @param none
	 * @return none
	 */
	public Player getCurrentPlayer(int i)
	{
		
		return players.get(i);
		
	}
	
	
	
	/**
	 * getList of Tiles
	 * 
	 * @param none
	 * @return none
	 */
	public ArrayList<Tile> getCurrentHandUI(int j)
	{
		ArrayList<Tile> x=new ArrayList<Tile>();
		ArrayList<Tile> old=getCurrentPlayer(j).getAllTileInHand();
		for(int i=0;i<old.size(); i++)
		{
			//String land, int knightsReq, String building, int points
			x.add(new Tile(old.get(i).getLandScape(),old.get(i).getQuantityKnights(), old.get(i).getBuildingStructure(), old.get(i).getWorth()));
		}
		
		return x;
		
		
		
		
	}

	/**
	 * see if gui is done
	 * 
	 * @param none
	 * @return none
	 */
	public boolean done()
	{
		if(_playsize != _size)return false;
		return true;
		
		
		
	}



	/**
	 * initialize frame display window for color/card selection per player
	 * 
	 * @param none
	 * @return none
	 */
	public static void makePlayers(int i, int count) {
		// Create and set up the window.
		System.out.println(i);
		playerScreen.get(i).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	
		getStartDeck(playerScreen.get(i).getContentPane(), i);
		
		playerScreen.get(i).pack();
		playerScreen.get(i).setTitle("Player " + count);	 
        
		
        if(i==0)
        {
        	playerScreen.get(i).setLocation(xOffsetA, yOffset);
        	xOffsetA+=playerScreen.get(i).getWidth();
            //yOffset+=150;
        }
        else if(i==1)
        {
        	playerScreen.get(i).setLocation(xOffsetA, yOffset);
        	//xOffset+=100;
            yOffset+=playerScreen.get(i).getHeight();
        }
        else if(i==2)
        {
        	playerScreen.get(i).setLocation(xOffsetB, yOffset);
        	xOffsetB+=playerScreen.get(i).getWidth();
           
        }
        else if(i==3)
        {
        	playerScreen.get(i).setLocation(xOffsetB, yOffset);
        	
        }
		if(i>0)
		{
			while(playerScreen.get(i-1).isVisible()){};
			playerScreen.get(i).setVisible(true);
		}
		else playerScreen.get(i).setVisible(true);
			
		
	
	}

	
	/**
	 * Add buttons to player color and card seletion frame display window
	 * 
	 * @param container	and player index
	 * @return none
	 */
	private static void getStartDeck(Container pane, final int i) {
		// Icon ico = new ImageIcon("ICONS/yellow.jpg");
		
		
		/***************************** MAKE COLOR BUTTONS ****************************/
		JPanel aDeck2 = new JPanel();
		if (c1 == null && c2 == null && c3 == null && c4 == null) {
			//System.out.println("yes 2");
			JButton blue = new JButton(new ImageIcon("ICONS/blue.jpg"));
			//JButton blue = new JButton(new ImageIcon("ICONS/RedKnight.png"));
			blue.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					if ((i + 1) == 1)
						c1 = Color.BLUE;
					else if ((i + 1) == 2 && !c1.equals(Color.BLUE))
						c2 = Color.BLUE;
					else if ((i + 1) == 3 && !c1.equals(Color.BLUE)
							&& !c2.equals(Color.BLUE))
						c3 = Color.BLUE;
					else if ((i + 1) == 4 && !c1.equals(Color.BLUE)
							&& !c2.equals(Color.BLUE) && !c3.equals(Color.BLUE))
						c4 = Color.BLUE;
					
					
					//JButton redKnight=new JButton(new ImageIcon("ICONS/RedKnight.png"));
					
					
					
				}

			});
			JButton red = new JButton(new ImageIcon("ICONS/red.jpg"));
			red.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					if ((i + 1) == 1)
						c1 = Color.RED;
					else if ((i + 1) == 2 && !c1.equals(Color.RED))
						c2 = Color.RED;
					else if ((i + 1) == 3 && !c1.equals(Color.RED)
							&& !c2.equals(Color.RED))
						c3 = Color.RED;
					else if ((i + 1) == 4 && !c1.equals(Color.RED)
							&& !c2.equals(Color.RED) && !c3.equals(Color.RED))
						c4 = Color.RED;
				}
			});
			JButton green = new JButton(new ImageIcon("ICONS/green.jpg"));
			green.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					if ((i + 1) == 1)
						c1 = Color.GREEN;
					else if ((i + 1) == 2 && !c1.equals(Color.GREEN))
						c2 = Color.RED;
					else if ((i + 1) == 3 && !c1.equals(Color.GREEN)
							&& !c2.equals(Color.GREEN))
						c3 = Color.GREEN;
					else if ((i + 1) == 4 && !c1.equals(Color.GREEN)
							&& !c2.equals(Color.GREEN)
							&& !c3.equals(Color.GREEN))
						c4 = Color.GREEN;
				}
			});
			JButton yellow = new JButton(new ImageIcon("ICONS/yellow.jpg"));
			yellow.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					if ((i + 1) == 1)
						c1 = Color.YELLOW;
					else if ((i + 1) == 2 && !c1.equals(Color.YELLOW))
						c2 = Color.YELLOW;
					else if ((i + 1) == 3 && !c1.equals(Color.YELLOW)
							&& !c2.equals(Color.YELLOW))
						c3 = Color.YELLOW;
					else if ((i + 1) == 4 && !c1.equals(Color.YELLOW)
							&& !c2.equals(Color.YELLOW)
							&& !c3.equals(Color.YELLOW))
						c4 = Color.YELLOW;
				}
			});
			aDeck2.add(green);
			aDeck2.add(red);
			aDeck2.add(blue);
			aDeck2.add(yellow);
		}
		else if (c1 != null && c2 == null && c3 == null && c4 == null) {
			System.out.println("yes");
			JButton blue = new JButton(new ImageIcon("ICONS/blue.jpg"));
			blue.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					if ((i + 1) == 1)
						c1 = Color.BLUE;
					else if ((i + 1) == 2 && !c1.equals(Color.BLUE))
						c2 = Color.BLUE;
					else if ((i + 1) == 3 && !c1.equals(Color.BLUE)
							&& !c2.equals(Color.BLUE))
						c3 = Color.BLUE;
					else if ((i + 1) == 4 && !c1.equals(Color.BLUE)
							&& !c2.equals(Color.BLUE) && !c3.equals(Color.BLUE))
						c4 = Color.BLUE;
				}
			});
			JButton red = new JButton(new ImageIcon("ICONS/red.jpg"));
			red.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					if ((i + 1) == 1)
						c1 = Color.RED;
					else if ((i + 1) == 2 && !c1.equals(Color.RED))
						c2 = Color.RED;
					else if ((i + 1) == 3 && !c1.equals(Color.RED)
							&& !c2.equals(Color.RED))
						c3 = Color.RED;
					else if ((i + 1) == 4 && !c1.equals(Color.RED)
							&& !c2.equals(Color.RED) && !c3.equals(Color.RED))
						c4 = Color.RED;
				}
			});
			JButton green = new JButton(new ImageIcon("ICONS/green.jpg"));
			green.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					if ((i + 1) == 1)
						c1 = Color.GREEN;
					else if ((i + 1) == 2 && !c1.equals(Color.GREEN))
						c2 = Color.RED;
					else if ((i + 1) == 3 && !c1.equals(Color.GREEN)
							&& !c2.equals(Color.GREEN))
						c3 = Color.GREEN;
					else if ((i + 1) == 4 && !c1.equals(Color.GREEN)
							&& !c2.equals(Color.GREEN)
							&& !c3.equals(Color.GREEN))
						c4 = Color.GREEN;
				}
			});
			JButton yellow = new JButton(new ImageIcon("ICONS/yellow.jpg"));
			yellow.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					if ((i + 1) == 1)
						c1 = Color.YELLOW;
					else if ((i + 1) == 2 && !c1.equals(Color.YELLOW))
						c2 = Color.YELLOW;
					else if ((i + 1) == 3 && !c1.equals(Color.YELLOW)
							&& !c2.equals(Color.YELLOW))
						c3 = Color.YELLOW;
					else if ((i + 1) == 4 && !c1.equals(Color.YELLOW)
							&& !c2.equals(Color.YELLOW)
							&& !c3.equals(Color.YELLOW))
						c4 = Color.YELLOW;
				}
			});
			if (c1.equals(Color.RED)) {
				aDeck2.add(green);
				aDeck2.add(blue);
				aDeck2.add(yellow);
			} else if (c1.equals(Color.BLUE)) {
				aDeck2.add(green);
				aDeck2.add(red);
				aDeck2.add(yellow);
			} else if (c1.equals(Color.YELLOW)) {
				aDeck2.add(green);
				aDeck2.add(red);
				aDeck2.add(blue);
			} else if (c1.equals(Color.GREEN)) {
				aDeck2.add(red);
				aDeck2.add(blue);
				aDeck2.add(yellow);
			}
		}
		else if (c1 != null && c2 != null && c3 == null && c4 == null) {
			JButton blue = new JButton(new ImageIcon("ICONS/blue.jpg"));
			blue.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					if ((i + 1) == 1)
						c1 = Color.BLUE;
					else if ((i + 1) == 2 && !c1.equals(Color.BLUE))
						c2 = Color.BLUE;
					else if ((i + 1) == 3 && !c1.equals(Color.BLUE)
							&& !c2.equals(Color.BLUE))
						c3 = Color.BLUE;
					else if ((i + 1) == 4 && !c1.equals(Color.BLUE)
							&& !c2.equals(Color.BLUE) && !c3.equals(Color.BLUE))
						c4 = Color.BLUE;
				}
			});
			JButton red = new JButton(new ImageIcon("ICONS/red.jpg"));
			red.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					if ((i + 1) == 1)
						c1 = Color.RED;
					else if ((i + 1) == 2 && !c1.equals(Color.RED))
						c2 = Color.RED;
					else if ((i + 1) == 3 && !c1.equals(Color.RED)
							&& !c2.equals(Color.RED))
						c3 = Color.RED;
					else if ((i + 1) == 4 && !c1.equals(Color.RED)
							&& !c2.equals(Color.RED) && !c3.equals(Color.RED))
						c4 = Color.RED;
				}
			});
			JButton green = new JButton(new ImageIcon("ICONS/green.jpg"));
			green.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					if ((i + 1) == 1)
						c1 = Color.GREEN;
					else if ((i + 1) == 2 && !c1.equals(Color.GREEN))
						c2 = Color.RED;
					else if ((i + 1) == 3 && !c1.equals(Color.GREEN)
							&& !c2.equals(Color.GREEN))
						c3 = Color.GREEN;
					else if ((i + 1) == 4 && !c1.equals(Color.GREEN)
							&& !c2.equals(Color.GREEN)
							&& !c3.equals(Color.GREEN))
						c4 = Color.GREEN;
				}
			});
			JButton yellow = new JButton(new ImageIcon("ICONS/yellow.jpg"));
			yellow.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					if ((i + 1) == 1)
						c1 = Color.YELLOW;
					else if ((i + 1) == 2 && !c1.equals(Color.YELLOW))
						c2 = Color.YELLOW;
					else if ((i + 1) == 3 && !c1.equals(Color.YELLOW)
							&& !c2.equals(Color.YELLOW))
						c3 = Color.YELLOW;
					else if ((i + 1) == 4 && !c1.equals(Color.YELLOW)
							&& !c2.equals(Color.YELLOW)
							&& !c3.equals(Color.YELLOW))
						c4 = Color.YELLOW;
				}
			});
			// c1=red
			if (c1.equals(Color.RED)) {
				if (c2.equals(Color.BLUE)) {
					aDeck2.add(green);
					aDeck2.add(yellow);
				} else if (c2.equals(Color.YELLOW)) {
					aDeck2.add(green);
					aDeck2.add(blue);
				} else if (c2.equals(Color.GREEN)) {
					aDeck2.add(blue);
					aDeck2.add(yellow);
				}
			} else if (c1.equals(Color.BLUE)) {
				if (c2.equals(Color.RED)) {
					aDeck2.add(green);
					aDeck2.add(yellow);
				} else if (c2.equals(Color.YELLOW)) {
					aDeck2.add(green);
					aDeck2.add(red);
				} else if (c2.equals(Color.GREEN)) {
					aDeck2.add(red);
					aDeck2.add(yellow);
				}
			} else if (c1.equals(Color.YELLOW)) {
				if (c2.equals(Color.BLUE)) {
					aDeck2.add(blue);
					aDeck2.add(red);
				} else if (c2.equals(Color.RED)) {
					aDeck2.add(green);
					aDeck2.add(blue);
				} else if (c2.equals(Color.GREEN)) {
					aDeck2.add(blue);
					aDeck2.add(red);
				}
			} else if (c1.equals(Color.GREEN)) {
				if (c2.equals(Color.BLUE)) {
					aDeck2.add(red);
					aDeck2.add(yellow);
				} else if (c2.equals(Color.YELLOW)) {
					aDeck2.add(red);
					aDeck2.add(blue);
				} else if (c2.equals(Color.RED)) {
					aDeck2.add(blue);
					aDeck2.add(yellow);
				}
			}
		}
		else if (c1 != null && c2 != null && c3 != null && c4 == null) {
			JButton blue = new JButton(new ImageIcon("ICONS/blue.jpg"));
			blue.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					if ((i + 1) == 1)
						c1 = Color.BLUE;
					else if ((i + 1) == 2 && !c1.equals(Color.BLUE))
						c2 = Color.BLUE;
					else if ((i + 1) == 3 && !c1.equals(Color.BLUE)
							&& !c2.equals(Color.BLUE))
						c3 = Color.BLUE;
					else if ((i + 1) == 4 && !c1.equals(Color.BLUE)
							&& !c2.equals(Color.BLUE) && !c3.equals(Color.BLUE))
						c4 = Color.BLUE;
				}
			});
			JButton red = new JButton(new ImageIcon("ICONS/red.jpg"));
			red.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					if ((i + 1) == 1)
						c1 = Color.RED;
					else if ((i + 1) == 2 && !c1.equals(Color.RED))
						c2 = Color.RED;
					else if ((i + 1) == 3 && !c1.equals(Color.RED)
							&& !c2.equals(Color.RED))
						c3 = Color.RED;
					else if ((i + 1) == 4 && !c1.equals(Color.RED)
							&& !c2.equals(Color.RED) && !c3.equals(Color.RED))
						c4 = Color.RED;
				}
			});
			JButton green = new JButton(new ImageIcon("ICONS/green.jpg"));
			green.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					if ((i + 1) == 1)
						c1 = Color.GREEN;
					else if ((i + 1) == 2 && !c1.equals(Color.GREEN))
						c2 = Color.RED;
					else if ((i + 1) == 3 && !c1.equals(Color.GREEN)
							&& !c2.equals(Color.GREEN))
						c3 = Color.GREEN;
					else if ((i + 1) == 4 && !c1.equals(Color.GREEN)
							&& !c2.equals(Color.GREEN)
							&& !c3.equals(Color.GREEN))
						c4 = Color.GREEN;
				}
			});
			JButton yellow = new JButton(new ImageIcon("ICONS/yellow.jpg"));
			yellow.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					if ((i + 1) == 1)
						c1 = Color.YELLOW;
					else if ((i + 1) == 2 && !c1.equals(Color.YELLOW))
						c2 = Color.YELLOW;
					else if ((i + 1) == 3 && !c1.equals(Color.YELLOW)
							&& !c2.equals(Color.YELLOW))
						c3 = Color.YELLOW;
					else if ((i + 1) == 4 && !c1.equals(Color.YELLOW)
							&& !c2.equals(Color.YELLOW)
							&& !c3.equals(Color.YELLOW))
						c4 = Color.YELLOW;
				}
			});
			// get colors
			// IF C1 IS RED
			if (c1.equals(Color.RED)) {
				if (c2.equals(Color.BLUE)) {
					if (c3.equals(Color.YELLOW)) {
						aDeck2.add(green);
					} else if (c3.equals(Color.GREEN)) {
						aDeck2.add(yellow);
					}
				} else if (c2.equals(Color.YELLOW)) {
					if (c3.equals(Color.GREEN)) {
						aDeck2.add(blue);
					} else if (c3.equals(Color.BLUE)) {
						aDeck2.add(green);
					}
				} else if (c2.equals(Color.GREEN)) {
					if (c3.equals(Color.YELLOW)) {
						aDeck2.add(blue);
					} else if (c3.equals(Color.BLUE)) {
						aDeck2.add(yellow);
					}
				}
			}
			// IF C1 IS GREEN
			if (c1.equals(Color.GREEN)) {
				if (c2.equals(Color.BLUE)) {
					if (c3.equals(Color.YELLOW)) {
						aDeck2.add(red);
					} else if (c3.equals(Color.RED)) {
						aDeck2.add(yellow);
					}
				} else if (c2.equals(Color.YELLOW)) {
					if (c3.equals(Color.RED)) {
						aDeck2.add(blue);
					} else if (c3.equals(Color.BLUE)) {
						aDeck2.add(red);
					}
				} else if (c2.equals(Color.RED)) {
					if (c3.equals(Color.YELLOW)) {
						aDeck2.add(blue);
					} else if (c3.equals(Color.BLUE)) {
						aDeck2.add(yellow);
					}
				}
			}
			// IF C1 IS BLUE
			if (c1.equals(Color.BLUE)) {
				if (c2.equals(Color.RED)) {
					if (c3.equals(Color.YELLOW)) {
						aDeck2.add(green);
					} else if (c3.equals(Color.GREEN)) {
						aDeck2.add(yellow);
					}
				} else if (c2.equals(Color.YELLOW)) {
					if (c3.equals(Color.GREEN)) {
						aDeck2.add(red);
					} else if (c3.equals(Color.RED)) {
						aDeck2.add(green);
					}
				} else if (c2.equals(Color.YELLOW)) {
					if (c3.equals(Color.YELLOW)) {
						aDeck2.add(red);
					} else if (c3.equals(Color.RED)) {
						aDeck2.add(yellow);
					}
				}
			}
			// IF C1 IS YELLOW
			if (c1.equals(Color.YELLOW)) {
				if (c2.equals(Color.BLUE)) {
					if (c3.equals(Color.RED)) {
						aDeck2.add(green);
					} else if (c3.equals(Color.GREEN)) {
						aDeck2.add(red);
					}
				} else if (c2.equals(Color.RED)) {
					if (c3.equals(Color.GREEN)) {
						aDeck2.add(blue);
					} else if (c3.equals(Color.BLUE)) {
						aDeck2.add(green);
					}
				} else if (c2.equals(Color.GREEN)) {
					if (c3.equals(Color.RED)) {
						aDeck2.add(blue);
					} else if (c3.equals(Color.BLUE)) {
						aDeck2.add(red);
					}
				}
			}
		}
		/****************************** MAKE BUTTONS TO CHOOSE FIRST CARD *************************************/
		/*JButton lake = new JButton(new ImageIcon("ICONS/lake_none.jpg"));
		lake.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				// Player(Color c, String land,String building)
				if ((i + 1) == 1 && c1 != null) {
					players.add(new Player(c1, "lake", "none", 1));
					playerScreen.get(i).dispose();
					done=true;
					++_playsize;
				} else if ((i + 1) == 2 && c2 != null && players.get(0) != null) {
					players.add(new Player(c2, "lake", "none", 2));
					playerScreen.get(i).dispose();
					++_playsize;
				} else if ((i + 1) == 3 && c3 != null && players.get(0) != null
						&& players.get(1) != null) {
					players.add(new Player(c3, "lake", "none", 3));
					playerScreen.get(i).dispose();
					++_playsize;
				} else if ((i + 1) == 4 && c4 != null && players.get(0) != null
						&& players.get(1) != null && players.get(2) != null) {
					players.add(new Player(c4, "lake", "none", 4));
					playerScreen.get(i).dispose();
					++_playsize;
				}
				// playerScreen.get(i).dispose();
			}
		});*/

		JButton mount = new JButton(new ImageIcon("ICONS/mountain_none.jpg"));
		mount.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if ((i + 1) == 1 && c1 != null) {
					players.add(new Player(c1, "mountain", "none", 1));
					playerScreen.get(i).dispose();
					++_playsize;
				} else if ((i + 1) == 2 && c2 != null && players.get(0) != null) {
					players.add(new Player(c2, "mountain", "none", 2));
					playerScreen.get(i).dispose();
				++_playsize;
				} else if ((i + 1) == 3 && c3 != null && players.get(0) != null
						&& players.get(1) != null) {
					players.add(new Player(c3, "mountain", "none", 3));
					playerScreen.get(i).dispose();
					++_playsize;
				} else if ((i + 1) == 4 && c4 != null && players.get(0) != null
						&& players.get(1) != null && players.get(2) != null) {
					players.add(new Player(c4, "mountain", "none", 4));
					playerScreen.get(i).dispose();
					++_playsize;
				}
				// playerScreen.get(i).dispose();
			}
		});
		JButton plainV = new JButton(new ImageIcon("ICONS/plain_village.jpg"));
		plainV.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if ((i + 1) == 1 && c1 != null) {
					players.add(new Player(c1, "plain", "village", 1));
					playerScreen.get(i).dispose();
					++_playsize;
				} else if ((i + 1) == 2 && c2 != null && players.get(0) != null) {
					players.add(new Player(c2, "plain", "village", 2));
					playerScreen.get(i).dispose();
					++_playsize;
				} else if ((i + 1) == 3 && c3 != null && players.get(0) != null
						&& players.get(1) != null) {
					System.out.println("plain village 3");
					players.add(new Player(c3, "plain", "village", 3));
					playerScreen.get(i).dispose();
					++_playsize;
				} else if ((i + 1) == 4 && c4 != null && players.get(0) != null
						&& players.get(1) != null && players.get(2) != null) {
					System.out.println("plain village 4");
					players.add(new Player(c4, "plain", "village", 4));
					playerScreen.get(i).dispose();
				++_playsize;
				}
				// playerScreen.get(i).dispose();
			}
		});
		JButton plainN = new JButton(new ImageIcon("ICONS/plain_none.jpg"));
		plainN.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				// System.out.println("4 quit");
				// System.exit(0);
				if ((i + 1) == 1 && c1 != null) {
					players.add(new Player(c1, "plain", "none", 1));
					playerScreen.get(i).dispose();
					++_playsize;
				} else if ((i + 1) == 2 && c2 != null && players.get(0) != null) {
					players.add(new Player(c2, "plain", "none", 2));
					playerScreen.get(i).dispose();
					++_playsize;
				} else if ((i + 1) == 3 && c3 != null && players.get(0) != null
						&& players.get(1) != null) {
					System.out.println("plain none  3");
					players.add(new Player(c3, "plain", "none", 3));
					playerScreen.get(i).dispose();
					++_playsize;
				} else if ((i + 1) == 4 && c4 != null && players.get(0) != null
						&& players.get(1) != null && players.get(2) != null) {
					System.out.println("plain none  4");
					players.add(new Player(c4, "plain", "none", 4));
					playerScreen.get(i).dispose();
					++_playsize;
				}
				// playerScreen.get(i).dispose();
			}
		});
		JPanel aDeck = new JPanel();
		//aDeck.add(lake);
		aDeck.add(mount);
		aDeck.add(plainV);
		aDeck.add(plainN);

		/************************************* MAKE TEXT *************************/
		JTextArea x = new JTextArea(3, 3);
		x.setEditable(false);

		if (i + 1 == 1) {
			x.append("    Please Select Player 1 first " + "\n");
			x.append("    1. Choose Color first" + "\n");
			x.append("    2. Choose First card next " + "\n");
		} else if (i + 1 == 2) {
			x.append("    Please Select Player 1 first, then select player 2"
					+ "\n");
			x.append("    1. Choose Color first, must not be same as player 1"
					+ "\n");
			x.append("    2. Choose First card next " + "\n");
		} else if (i + 1 == 3) {
			x.append("    Please Select Player 1 first, then select player 2, then  player 3"
					+ "\n");
			x.append("    1. Choose Color first, must not be same as player 1 or 2"
					+ "\n");
			x.append("    2. Choose First card next " + "\n");
		} else if (i + 1 == 4) {
			x.append("    Please Select Player 1 first, then select player 2,  then  player 3, then player 4 "
					+ "\n");
			x.append("    1. Choose Color first, must not be same as player 1, 2, or 3"
					+ "\n");
			x.append("    2. Choose First card next " + "\n");
		}

		/******************************** ADD TO DISPLAY WINDOW ****************/
		pane.add(x, BorderLayout.NORTH);
		pane.add(aDeck2, BorderLayout.CENTER);
		pane.add(aDeck, BorderLayout.SOUTH);
	}


	/**
	 * handle events for combo box events
	 * 
	 * @param itemevent
	 * @return none
	 */
	public void itemStateChanged(ItemEvent evt) {
		// TODO
		CardLayout cl = (CardLayout) (play.getLayout());
		cl.show(play, (String) evt.getItem());
	}


}